<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="author" content="featon inc.">
    <link rel="stylesheet" href="/static/vendor/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/vendor/bootstrap/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="/static/vendor/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/vendor/jqPagination/css/jqpagination.css">

    <link href="/static/vendor/jquery-easyui/themes/default/tree.css" rel="stylesheet">
    <link href="/static/vendor/jquery-easyui/themes/icon.css" rel="stylesheet">
    <link href="/static/vendor/jquery-ui/themes/base/jquery.ui.all.css" rel="stylesheet">

    <link rel="stylesheet" href="/static/vendor/skin/ftskin.css">

    <title>信息列表</title>
</head>

<body>
<div class="ft-subpage-wrapper container-fluid">

    <!-- 左导航开始	-->
    <div id="ftsidebar-subpage" style="overflow:auto;" class="ft-sidebar-box-subpage">
        <div class="leftTree-box">
            <ul id="leftTree" class="easyui-tree" animate="true">

            </ul>
        </div>
    </div>
    <!-- 左导航结束	-->

    <!-- 主窗口开始	-->
    <div id="ftmainBox" class="ft-mainBox">
        <div class="row">
            <div class="container-fluid">
                <div class="col-lg-12">
                    <div class="tools-box">
                        <button type="button" class="btn btn-info" onclick="openAddPage()"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 添加</button>
                        <button type="button" class="btn btn-warning" onclick="updateRecord(table,'dept_id','openUpdatePage()');"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span> 修改</button>
                        <button type="button" class="btn btn-danger" onclick="deleteRecord(table,'dept_id','deleteObject()');"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> 删除</button>
                        <button type="button" class="btn btn-info" onclick="publicSelectCheckbox(table,'dept_id','openSelectSinglDeptPage(\'选择组织机构\',\'moveObject\')');"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> 移动</button>
                        <button type="button" class="btn btn-success" onclick="sortRecord(table,'dept_id','sortObject()');"><span class="glyphicon glyphicon-floppy-saved" aria-hidden="true"></span> 保存排序</button>
                    </div>
                </div>
            </div>
        </div>


        <div class="row">
            <div class="container-fluid">
                <div class="col-lg-12" id="table">

                </div>
            </div>
        </div>

        <div class="row">
            <div class="container-fluid">
                <div id="turn">

                </div>
            </div>
        </div>

    </div>
    <!-- 主窗口结束	-->
    <input type="hidden" th:id="dept_id" th:value="${dept_id}"  />

</div>
<script src="/static/vendor/jquery/jquery-2.1.3.min.js"></script>
<script src="/static/vendor/bootstrap/js/bootstrap.min.js"></script>

<script src="/static/vendor/jquery-ui/minified/jquery-ui.min.js"></script>
<script src="/static/vendor/jquery-easyui/jquery.easyui.min.js"></script>

<link rel="stylesheet" href="/static/vendor/custom-scrollbar/jquery.mCustomScrollbar.min.css">
<script src="/static/vendor/custom-scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>

<script src="/static/vendor/jqPagination/js/jquery.jqpagination.min.js"></script>
<script src="/static/vendor/skin/js/ft-ui.js"></script>
<script src="/static/vendor/skin/js/tree-util.js"></script>
<script src="/static/vendor/skin/js/table-common.js"></script>
<script src="/static/vendor/skin/js/java.js"></script>
<script src="/static/vendor/skin/js/jquery.c.js"></script>
<script>
    var dept_id = $("#dept_id").val();
    var tp = new TurnPage();
    var table = new Table();
    table.table_name = "table_list";
    var beanList = null;
    var jsonData;

    $(document).ready(function(){
        init_page();   //初始化页面内各BOX高度

        //table_input_init("dataTables-example-01"); //初始化input全选
        $("#ftsidebar-subpage").mCustomScrollbar({
            theme:"minimal-dark"
        });

        initTable();
        showDeptTree();

        loadListble();
    });

    $(window).resize(function(){
        init_page();
    });

    //初始化页面内各BOX高度
    function init_page()
    {
        var window_height = $(window).height();

        $("#ftmainBox").css("height",window_height-38);
        $("#ftsidebar-subpage").css("height",window_height-58);

    }

    function showDeptTree()
    {
        top.ajax.simple("/dept/getDeptTreeJsonStr/1",{},showDeptTreeHandl);
    }

    function showDeptTreeHandl(obj)
    {
        json_data = obj;
        setLeftMenuTreeJsonData(json_data);
        initMenuTree();
        treeNodeSelected(dept_id);
    }

    function initMenuTree()
    {
        $('#leftTree').tree({
            onClick:function(node){
                changeDeptListTable(node.id);
            }
        });

    }

    //点击树节点,修改组织机构列表数据
    function changeDeptListTable(m_id){
        dept_id = m_id;
        loadListble();
    }

    function initTable(){

        var colsMap = new Map();
        var colsList = new List();

        colsList.add(setTitleClos("dept_id","部门ID","80px","","",""));
        colsList.add(setTitleClos("dept_name","部门全称","200px","","",""));
        colsList.add(setTitleClos("action_col","操作","120px","","",""));
        colsList.add(setTitleClos("sort_col","排序","100px","","",""));
        colsList.add(setTitleClos("dept_sortname","部门简称","200px","","",""));
        //colsList.add(setTitleClos("dept_code","部门编码","100px","","",""));
        colsList.add(setTitleClos("dq_yw_name","所属业务行政区划","200px","","",""));
        //colsList.add(setTitleClos("dept_type","部门类型","120px","","",""));
        colsList.add(setTitleClos("cell_space"," "," ","","",""));

        table.setColsList(colsList);
        table.setAllColsList(colsList);
        table.enableSort=false;//禁用表头排序
        table.onSortChange = showList;
        table.show("table");//里面参数为外层div的id
    }

    function loadListble()
    {
        showDeptTree();
        showList();
        showTurnPage();
    }

    function showList(){

        beanList = top.ajax.syncl("/dept/getChildDeptListByID/"+dept_id,"");

        curr_bean = null;
        table.setBeanList(beanList,"td_list");//设置列表内容的样式
        table.show("table");

        tp.total = beanList.length;

        table.getCol("action_col").each(function(i){
            if(i>0)
            {
                $(this).html('<a href="javascript:openUpdatePage('+beanList[i-1].dept_id+')">编辑</a>&nbsp;&nbsp;<a href="javascript:deleteSingleObject('+beanList[i-1].dept_id+')">删除</a>');
            }
        });

        table.getCol("sort_col").each(function(i){
            if(i>0)
            {
                $(this).html(getSortColStr());
            }
        });

        /* table.getCol("dept_type").each(function(i){
            if(i>0)
            {
                switch(beanList[i-1].dept_type)
                {
                    case 0:$(this).text('一般部门');break;
                    case 1:$(this).text('免疫部门');break;
                    case 2:$(this).text('检疫部门');break;
                    case 3:$(this).text('屠宰场部门');break;
                    case 4:$(this).text('诊疗机构');break;
                    case 9:$(this).text('检疫免疫部门');break;
                }
            }
        }); */
        table_input_init(table.table_name);
    }

    function showTurnPage(){

        tp.show("turn","simple");
        tp.onPageChange = showList;
    }

    function openAddPage()
    {
        //modelWindow.openFrameWindow('维护组织机构','/sys/cs/org/dept/dept_add.html?parentID='+dept_id,600,350);
        top.addTab('/dept/go_dept_add?parentID='+dept_id);
    }

    function openUpdatePage(id)
    {
        var sel_id = '';
        if(id != '' && id != null)
        {
            sel_id = id;
        }else
            sel_id = table.getSelecteCheckboxValue("dept_id");
        //modelWindow.openFrameWindow("维护组织机构","/sys/cs/org/dept/dept_add.html?parentID="+dept_id+"&dept_id="+sel_id,600,350);
        top.addTab("/dept/go_dept_add?parentID="+dept_id+"&dept_id="+sel_id);
    }

    //打开组织机构选择窗口
    function openSelectSinglDeptPage(title,handl_name)
    {
        modelWindow.openFrameWindow(title,"/dept/go_select_single_dept?handle_name="+handl_name,450,410);
    }

    function moveObject(parent_id)
    {
        if(parent_id != "" && parent_id != null)
        {
            var selectIDS = table.getSelecteCheckboxValue("dept_id");
            var om = new Map();
            om.put("parent_id",parent_id+"");
            om.put("dept_ids",selectIDS);
            //传递多个参数可用map装载,最后使用toJSON转成json对象
            if(top.ajax.syncl("/dept/move",om.toJSON()))
            {
                modelWindow.alert("组织机构"+top.CMSLang.Move_success);
                loadListble()
                //showDeptTree();
            }else
            {
                modelWindow.error("组织机构"+CMSLang.Move_fail);
                return;
            }
        }
    }

    function deleteObject(id)
    {
        var sel_id = '';
        if(id != '' && id != null)
        {
            sel_id = id;
        }else
            sel_id = table.getSelecteCheckboxValue("dept_id");
        //传递单个参数可直接写json对象
        if(top.ajax.syncl("/dept/del",{"id":sel_id}))
        {
            modelWindow.alert("组织机构信息"+top.CMSLang.Delete_success);
            deleteTreeNode(sel_id);
            loadListble();
        }else
        {
            modelWindow.error("组织机构信息"+top.CMSLang.Delete_fail);
        }
    }

    function deleteSingleObject(id)
    {
        modelWindow.confirm("是否删除该条记录","deleteObject('"+id+"')")
    }

    function sortObject()
    {
        var dept_ids = table.getAllCheckboxValue("dept_id");
        if(dept_ids != "" && dept_ids != null)
        {
            if(top.ajax.syncl("/dept/sort",{"id":dept_ids}))
            {
                modelWindow.alert(top.CMSLang.Sort_success);
                showDeptTree();
            }
            else
            {
                modelWindow.error(top.CMSLang.Sort_fail);
                return;
            }
        }
    }
</script>
</body>
</html>
